	<?php 
//引进配置信息
include '../include/init.php';
//引入数据库配置信息
include '../include/mysql.config.php';
//引入公共函数
include '../include/common.fun.php';

islogin();

//步骤2
$id = isset($_GET['id'])?$_GET['id']+0:0;


//步骤3

$sql="SELECT * from wd_case LEFT JOIN wd_case_cat ON wd_case.case_cat_id=wd_case_cat.case_cat_id where case_id=$id";
$case=$db->getOne($sql);
if(!$case){
	alert('非法访问','index.php');
	exit;
}

// dump($service);

if ($_POST){
	$title=$_POST['title'];
	$author=$_POST['author'];
	$content=$_POST['content'];
	$address=$_POST['address'];
	$catId=$_POST['cid'];
	
		$date=array(
			'case_name' => $title,
			'case_content' => $content,
			'case_cat_id'=>$catId
		);

	if ($_FILES) {
		if ($_FILES['img1']['error']!=4) {
			$res=upload('img1','../uploads/case');
			if($res['error']==1){
				alert($res['msg']);exit;
			}elseif ($res['error']==2) {
				$date['case_img']=$res['path'];
				$thumb_img=thumb('../uploads/case/'.$res['path'],'../uploads/case_thumb',250,250);
				$date['case_img_thumb']=$thumb_img['path'];
			}
		}
	}
	


	//步骤7
	$where = 'case_id='.$id;
	$result = $db->update('wd_case',$date,$where);


	if($result){
		if(isset($res) && $res['error']==2){
			unlink(SERVICE_PATH_CASE_THUMB.$case['case_img']);
			unlink(SERVICE_PATH_CASE_THUMB.$case['case_img_thumb']);
		}
		alert('修改成功','case_list.php');
	}else{
		alert('修改失败');
	}
}

include 'view/case_edit.php';